package com.vren.addressParse.modules.addressParse;

import com.vren.addressParse.common.domain.ResponseResult;
import com.vren.addressParse.modules.addressParse.domain.address.Address;
import com.vren.addressParse.modules.addressParse.domain.dto.AddressDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName:AddressParse
 * @Description:
 * @Author: vren
 * @Date: 2022/6/24 13:57
 */
@RequestMapping("/addressParse")
@RestController
@Api(tags = {"地址解析"})
public class AddressParseController {

    @Autowired
    private ParseService parseService;

    @RequestMapping(value = "/single", method = RequestMethod.POST)
    @ApiOperation("单条地址信息解析")
    public ResponseResult<Address> parse(@RequestBody @Valid AddressDTO dto) {
        return ResponseResult.success("解析成功", parseService.parse(dto));
    }

    @RequestMapping(value = "/batch", method = RequestMethod.POST)
    @ApiOperation("批量解析地址信息")
    public ResponseResult<List<Address>> batch(@RequestBody @Valid List<AddressDTO> list) {
        return ResponseResult.success("解析成功", parseService.batch(list));
    }

    @RequestMapping(value = "/analysisExcel", method = RequestMethod.POST)
    @ApiOperation("导入表格 批量解析地址信息")
    public ResponseResult<List<Address>> analysisExcel(@RequestPart("excel") MultipartFile excel) {
        return ResponseResult.success("解析成功", parseService.analysisExcel(excel));
    }
}
